﻿using System;
using System.Diagnostics;

namespace DasherBci
{
    public static class EegCoordinateCalculator
    {
        // Generates coordinates based on the detected action, the action's power and current vector position.
        public static CoordinatePair CalculateCoordinates(TrainedAction action, double actionPower, CoordinatePair currentPosition)
        {
            Debug.Assert(action != TrainedAction.Unset);

            if (action == TrainedAction.Neutral)
            {
                return currentPosition;
            }
            
            if (action == TrainedAction.Up)
            {
                if (currentPosition.Y < DasherSettings.YCoordinateValueMaximum/4)
                {
                    return currentPosition;
                }
                return new CoordinatePair(Math.Round(currentPosition.X, 0), Math.Round(currentPosition.Y - 1, 0));
            }
            
            if (action == TrainedAction.Down)
            {
                if (currentPosition.Y > DasherSettings.YCoordinateValueMaximum / 4)
                {
                    return currentPosition;
                }
                return new CoordinatePair(Math.Round(currentPosition.X, 0), Math.Round(currentPosition.Y + 1, 0));
            }

            throw new Exception("Invalid action.");
        }
    }
}
